A long time ago,
the Egyptians discovered that a triangle with sides of length 3, 4 and 5 had a
right angle as its largest angle. You need to determine if other triangles have
a similar property.
Input. Consists of several test cases, followed by
a line containing 0 0 0. Each test case includes three positive integers, each
less than 30000, representing the lengths of the sides of a triangle.
Output. For each test case, print a line containing “right” if the triangle is a right
triangle, and “wrong” if the
triangle is not a right triangle.
Sample
input |
Sample
output |
6 8 10 25 52 60 5 12 13 0 0 0 |
right wrong right |
loops
Let a, b, c be the sides of a triangle. A triangle is a right triangle if one of the following equalities
holds:
·
a2 = b2 + c2 (the hypotenuse is the side a)
·
b2 = a2 + c2 (the hypotenuse is the side b)
·
ñ2 = a2 + b2 (the hypotenuse is the side ñ)
Read the input data until
the end of the file.
while(scanf("%d %d %d",&a,&b,&c))
{
If there are three zeros, terminate the program.
if (a + b + c == 0) break;
Check if the triangle is a right triangle. Depending on the result, print the answer.
if ((a * a + b * b == c * c) ||
(a * a + c * c
== b * b) ||
(b * b + c * c
== a * a))
puts("right");
else
puts("wrong");
}
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new
Scanner(System.in);
while(con.hasNextInt())
{
int a = con.nextInt();
int b = con.nextInt();
int c = con.nextInt();
if (a + b + c == 0) break;
if ((a * a + b * b == c * c) ||
(a * a + c * c == b * b) ||
(b * b + c * c == a * a))
System.out.println("right");
else
System.out.println("wrong");
}
con.close();
}
}
Read the input data until
the end of the file.
while True:
a, b, c = map(int, input().split())
If there are three zeros, terminate the program.
if a + b + c == 0: break
Check if the triangle is a right triangle. Depending on the result, print the answer.
if (a * a + b * b == c * c) or (a * a + c * c == b *
b) or
(b * b + c * c == a *
a):
print("right");
else:
print("wrong")